<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <h1>{{user.fullName}}</h1>
        <h1>{{reversedMessage}}</h1>
    </div>
    <script src="./vue.js"></script>
    <script>
        const vm = new Vue({
            el: '#app',
            data: {
                msg: 'hello world',
                user: {
                    firstName: '诸葛',
                    lastName: '亮',
                    fullName: ''
                }
            },
            computed: {
                reversedMessage: function () {
                    return this.msg.split('').reverse().join('')
                }
            },
            watch: {
                'user': {
                    handler: function (newValue, oldValue) {
                        this.user.fullName = newValue.firstName + newValue.lastName
                    },
                    deep: true,
                    immediate: true
                }
            }
        });

        // vm.$watch('user', function (newValue, oldValue) {
        //     this.user.fullName = newValue.firstName + newValue.lastName
        // }, {
        //     immediate: true,
        //     deep: true
        // });
    </script>
</body>
</html>